﻿using MediatR;
using TaskProject.Application.Command.BOM;
using TaskProject.Domain.BOM;
using TaskProject.ErrorCode;
using TaskProject.InfrasIntructure.Interface;

namespace TaskProject.Application.Handler.BOM
{
    public class GetProductHandler : IRequestHandler<GetProductCommand, APIResult<List<ProductModel>>>
    {
        IBaseRepository<ProductModel> proRepo;

        public GetProductHandler(IBaseRepository<ProductModel> proRepo)
        {
            this.proRepo = proRepo;
        }

        public Task<APIResult<List<ProductModel>>> Handle(GetProductCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<ProductModel>> res = new APIResult<List<ProductModel>>();
            var pros=proRepo.GetAll().Where(c=>!c.IsDel).ToList();
            res.Msg = "查询产品信息成功";
            res.Code=APIEnum.Success;
            res.Data = pros;
            return Task.FromResult(res);
        }
    }
}
